const {
  override,
  fixBabelImports,
  addWebpackAlias,
  addLessLoader,
} = require("customize-cra");
const path = require("path");
const aliasPath = require("./aliasPath");
const antdThemeOption = require("./src/assets/styles/theme/base.js");

module.exports = override(
  // 路径别名
  addWebpackAlias({
    ...aliasPath,
  }),
  // ant 按需加载
  fixBabelImports("import", {
    libraryName: "antd",
    libraryDirectory: "es",
    style: true,
  }),
  addLessLoader({
    javascriptEnabled: true,
    modifyVars: antdThemeOption, // 主题样式
  }),
  (config) => {
    const loaders = config.module.rules.find((rule) => Array.isArray(rule.oneOf),).oneOf;
    loaders[7].use.push({
      loader: "style-resources-loader",
      options: {
        patterns: path.resolve(__dirname, "src/assets/styles/common.less"),
      },
    });
    return config;
  },
);
